package edu.hawaii.duedates;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import edu.hawaii.duedates.book.Book;
import edu.hawaii.duedates.user.User;

/**
 * A suite of tests for DueDates objects:  Library, User, Book, UserLibraryInfo.
 * 
 * @author Ronn Reeves and Robin E. Raqueno
 */
public class TestDueDates {

  /**
   * Tests the Book class.
   */
  @Test
  public void testBook() {
    String title = "Title";
    String date = "10/20/2008";
    String library = "Test library";
    Book book = new Book( title, date, library);
    book.setDueDate(date);
    book.setLibrary(library);
    book.setTitle(title);
    assertEquals("Book.toString() test failed.", book.toString(), book.getTitle());
    assertEquals("Book.getTitle() test failed.", title, book.getTitle());
    assertEquals("Book.getDueDate() test failed.", "10-20-08", book.getDueDate());
    assertEquals("Book.getLibrary() test failed.", library, book.getLibrary());
  }
  
  /**
   * Tests the Library class.
   */
  /*
  @Test
  public void testLibrary() {
    Library library = new Library(null, null, null, null);
    library.setDateColumn("DATE");
    library.setFormName("Form");
    library.setLoginErrorMessage("login Error");
    library.setLoginLink("login link");
    library.setName("Bob");
    library.setNoBorrowedItemsMessage("no items");
    library.setPasswordField("password");
    library.setSiteUrl("url");
    library.setSummaryLink("summary");
    library.setTitleColumn("title column");
    library.setUserIdField("user field");
    library.setValid(true);
    assertEquals("Library.getDateColumn() test failed.", "DATE", library.getDateColumn());
    assertEquals("Library.getFormName() test failed.", "Form", library.getFormName());
    assertEquals("Library.getFormName() test failed.", 
      "login Error", library.getLoginErrorMessage());
    assertEquals("Library.getLoginLink() test failed.", "login link", library.getLoginLink());
    assertEquals("Library.getName() test failed.", "Bob", library.getName());
    assertEquals("Library.getPasswordField() test failed.", "password", library.getPasswordField());
    assertEquals("Library.getSiteURL() test failed.", "url", library.getSiteUrl());
    assertEquals("Library.getSummaryLink() test failed.", "summary", library.getSummaryLink());
    assertEquals("Library.getTitleColumn() test failed.", "title column", library.getTitleColumn());
    assertEquals("Library.getUserIdField() test failed.", "user field", library.getUserIdField());
    assertTrue("Library.isValid() test failed.", library.isValid());
    assertEquals("Library.getNoBorrowedItemsMessage() test failed.", 
      "no items", library.getNoBorrowedItemsMessage());
    assertEquals("Library.toString() test failed.", "Bob (url)", library.toString());
  }
  */

  /**
   * Tests the User class.
   */
  @Test
  public void testUser() {
    String userId = "uid";
    String password = "pwd";
    User user = new User(null, null);
    user.setUserID(userId);
    user.setPassword(password);
    user.setValid(true);
    assertEquals("User.getUserID() test failed.", userId, user.getUserID());
    assertEquals("User.getPassword() test failed.", password, user.getPassword());
    assertTrue("User.isValid() test failed.", user.isValid());
    assertEquals("User.toString() test failed.", userId, user.toString());
  }
  
  /**
   * Tests the UserLibraryInfo class.
   */
  /*
  @Test
  public void testUserLibraryInfo() {
    // Create User
    // User user = new User("uid", "pwd");
    
    // Create attributes for the Hawaii State Library System

    // Create attributes for the University of Hawaii Library System
    String uhName = "UH Library System";
    String uhUrlSite = "http://uhmanoa.lib.hawaii.edu/cgi-bin/Pwebrecon.cgi";
    String uhUrlArgs = "?DB=local&PAGE=pbLogon";
    String uhUrl = uhUrlSite + uhUrlArgs;
    String uhForm = "logonpage";
    String uhPasswordField = "LN";
    String uhUserField = "BC";
    String uhLoginError = "Sorry, Login unsuccessful";
    String uhNoItems = "You have no items checked out.";
    String uhTitleCol = "Item";
    String uhDateCol = "Status";
    Library library = new Library(uhName, uhUrl, uhPasswordField, uhUserField);
    // Add form name, login error message, and no items message attributes to UH Library
    library.setFormName(uhForm);
    library.setLoginErrorMessage(uhLoginError);
    library.setNoBorrowedItemsMessage(uhNoItems);
    library.setTitleColumn(uhTitleCol);
    library.setDateColumn(uhDateCol);

    UserLibraryInfo uli = new UserLibraryInfo(user, library);
    List<Book> books = new ArrayList<Book>();
    uli.setBooks(books);
    uli.setValid(true);
    
    assertEquals("UserLibraryInfo.getLibrary() test failed.", uli.getLibrary(), library);
    assertEquals("UserLibraryInfo.getUser() test failed.", uli.getUser(), user);
    assertEquals("UserLibraryInfo.getBooks() test failed.", uli.getBooks(), books);
    assertTrue("UserLibraryInfo.isValid() test failed.", uli.isValid());
    assertEquals("UserLibraryInfo.toString() test failed.", 
      uli.toString(), "UH Library System - uid");
    
    uli.setLibrary(library);
    Library altLibrary = uli.getLibrary();
    uli.setUser(user);
    User altUser = uli.getUser();
    
    assertEquals("UserLibraryInfo.getLibrary() test failed for alternate.", altLibrary, library);
    assertEquals("UserLibraryInfo.getUser() test failed for alternate.", altUser, user);
  }
  */
}
